package org.alex.samples.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Utils {
	public static String getMD5Code(String password) {
		String result = null;
		result = new String(password);
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			result = byteToString(md.digest(result.getBytes()));
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return result;
	}
	
	public static String byteToString(byte[] buffer) {
		StringBuilder builder = new StringBuilder();
		for(int i = 0; i < buffer.length; i++) {
			builder.append(buffer[i]);
		}
		return builder.toString();
	}
}
